home *** CD-ROM | disk | FTP | other *** search
/ Teach Yourself Web Publi…sional Reference Edition) / Teach Yourself Web Publishing HTML 3.2.iso / mac / iso9660 / SOURCE / CHAP25 / TICKJAVA.ZIP / TickerT.java < prev   
Encoding:
Java Source  |  1996-04-26  |  8.9 KB  |  573 lines

  1. /*                    TickerT.class  version 1.1                        */
  2.  
  3. /*          Developed by Wes Tatters <wtatters@world.net>               */
  4.  
  5. /*  This program is released into the Public Domain - 27 January 1996   */
  6.  
  7.  
  8.  
  9. import java.applet.*;
  10.  
  11. import java.awt.* ;
  12.  
  13.  
  14.  
  15. public class TickerT extends NoFlickerApplet implements Runnable {
  16.  
  17.     Thread tkthread = null;
  18.  
  19.     int tkspd = 1;
  20.  
  21.  
  22.  
  23.     String tktitle  = "";
  24.  
  25.     String tkfname = "TimesRoman";
  26.  
  27.     int tkfsz = 12;
  28.  
  29.     Font tkfont = null;
  30.  
  31.  
  32.  
  33.     int tktitlepos = 0;
  34.  
  35.     int tktitlehgt = 0;
  36.  
  37.     int tktitleasc = 0;
  38.  
  39.     int tktmargin = 0;
  40.  
  41.     int tkmargin = 0;
  42.  
  43.     int tktgap = 0;
  44.  
  45.  
  46.  
  47.     int tkcolor = 0;
  48.  
  49.     Color tktitlecolor;
  50.  
  51.     Color tkboxcolor;
  52.  
  53.     Color tktextcolor;
  54.  
  55.     Color tktextbackcolor;
  56.  
  57.     Color tkbordercolor;
  58.  
  59.  
  60.  
  61.     String tkbox = "3D"; 
  62.  
  63.  
  64.  
  65.     String tkwrap = "No";
  66.  
  67.     int tkwrapwth = 0;
  68.  
  69.     String tkwraptext = " * ";
  70.  
  71.     String tktext = "Exercise - ticker tape";
  72.  
  73.     String tkwork = "";
  74.  
  75.     int tktemp = 0;
  76.  
  77.     int tkoffset = 0;
  78.  
  79.     String tktfname = "TimesRoman";
  80.  
  81.     int tktfsz = 12;
  82.  
  83.     Font tktfont = null;
  84.  
  85.  
  86.  
  87.     String tkdirection = "Left";
  88.  
  89.     Dimension tksize = null;
  90.  
  91.     int tktextwth = 0;
  92.  
  93.     int tktexthgt = 0;
  94.  
  95.     int tktextasc = 0;
  96.  
  97.     int tktextpos = 0;
  98.  
  99.     int tkpos = -63000;
  100.  
  101.  
  102.  
  103.  
  104.  
  105. public void init() {
  106.  
  107.     String getval = null;
  108.  
  109.  
  110.  
  111.     getval = getParameter("tkmargin");
  112.  
  113.     tkmargin = (getval == null ) ? tkmargin : (Integer.valueOf(getval).intValue());
  114.  
  115.  
  116.  
  117.     getval = getParameter("tktmargin");
  118.  
  119.     tktmargin = (getval == null ) ? tktmargin : (Integer.valueOf(getval).intValue());
  120.  
  121.  
  122.  
  123.     getval = getParameter("tktgap");
  124.  
  125.     tktgap = (getval == null ) ? 3 : (Integer.valueOf(getval).intValue());
  126.  
  127.     tktgap = (tktgap <= 3 ) ? 3 : tktgap;
  128.  
  129.  
  130.  
  131.     getval = getParameter("tktitle");
  132.  
  133.     if ( getval == null ) {
  134.  
  135.        tktitle = "";
  136.  
  137.        tkbox = "";
  138.  
  139.        }
  140.  
  141.     else {
  142.  
  143.        tktitle = getval;
  144.  
  145.        tkbox = "3D";
  146.  
  147.     }
  148.  
  149.  
  150.  
  151.     getval = getParameter("tkbox");
  152.  
  153.     tkbox = (getval == null ) ? tkbox : getval;
  154.  
  155.  
  156.  
  157.     getval = getParameter("tktfname");
  158.  
  159.     tktfname = (getval == null) ? tktfname : getval ;
  160.  
  161.     getval = getParameter("tktfsz");
  162.  
  163.     tktfsz = (getval == null ) ? tktfsz : (Integer.valueOf(getval).intValue());
  164.  
  165.     tktfont = new java.awt.Font( tktfname, Font.BOLD, tktfsz ) ;
  166.  
  167.  
  168.  
  169.     getval = getParameter("tktitlecolor");
  170.  
  171.     tkcolor = ( getval == null ) ?  0x000000 : (Integer.parseInt ( getval.substring(1) , 16 ));
  172.  
  173.     tktitlecolor = new Color( tkcolor );
  174.  
  175.  
  176.  
  177.     getval = getParameter("tkboxcolor");
  178.  
  179.     tkcolor = ( getval == null ) ?  0xC0C0C0 : (Integer.parseInt ( getval.substring(1) , 16 ));
  180.  
  181.     tkboxcolor = new Color( tkcolor );
  182.  
  183.  
  184.  
  185.     getval = getParameter("tkbordercolor");
  186.  
  187.     tkcolor = ( getval == null ) ?  tkcolor : (Integer.parseInt ( getval.substring(1) , 16 ));
  188.  
  189.     tkbordercolor = new Color( tkcolor );
  190.  
  191.  
  192.  
  193.     getval = getParameter("tktextcolor");
  194.  
  195.     tkcolor = ( getval == null ) ?  0x000000 : (Integer.parseInt ( getval.substring(1) , 16 ));
  196.  
  197.     tktextcolor = new Color( tkcolor );
  198.  
  199.  
  200.  
  201.     getval = getParameter("tktextbackcolor");
  202.  
  203.     tkcolor = ( getval == null ) ? 0xFFFFFF : (Integer.parseInt ( getval.substring(1) , 16 ));
  204.  
  205.     tktextbackcolor = new Color( tkcolor );
  206.  
  207.  
  208.  
  209.     getval = getParameter("tkwrap");
  210.  
  211.     tkwrap = (getval == null ) ? tkwrap : getval;
  212.  
  213.  
  214.  
  215.     getval = getParameter("tkseparator");
  216.  
  217.     tkwraptext = (getval == null ) ? tkwraptext : getval;
  218.  
  219.  
  220.  
  221.     getval = getParameter("tktext");
  222.  
  223.     tktext = (getval == null ) ? tktext : getval;
  224.  
  225.     getval = getParameter("tkfname");
  226.  
  227.     tkfname = (getval == null) ? tkfname : getval ;
  228.  
  229.     getval = getParameter("tkfsz");
  230.  
  231.     tkfsz = (getval == null ) ? tkfsz : (Integer.valueOf(getval).intValue());
  232.  
  233.     tkfont = new java.awt.Font( tkfname, Font.PLAIN, tkfsz ) ;
  234.  
  235.  
  236.  
  237.     getval = getParameter("tkspd");
  238.  
  239.     tkspd = (getval == null ) ? tkspd : (Integer.valueOf(getval).intValue());
  240.  
  241.  
  242.  
  243.     getval = getParameter("tkdirection");
  244.  
  245.     tkdirection = "Left";
  246.  
  247.     tkpos  =  -63000 ;
  248.  
  249.  
  250.  
  251.     if ( getval != null ) {
  252.  
  253.        if ( getval.equalsIgnoreCase( "Right") ) {
  254.  
  255.           tkdirection = "Right";
  256.  
  257.           tkpos  = 63000;
  258.  
  259.           }
  260.  
  261.        if ( getval.equalsIgnoreCase( "R") ) {
  262.  
  263.           tkdirection = "Right";
  264.  
  265.           tkpos  = 63000;
  266.  
  267.           }
  268.  
  269.        }
  270.  
  271.  
  272.  
  273.     this.setBackground( tktextbackcolor );
  274.  
  275.     }
  276.  
  277.  
  278.  
  279. public void start() {
  280.  
  281.     tkthread = new Thread(this);
  282.  
  283.     tkthread.start();
  284.  
  285.     }
  286.  
  287.  
  288.  
  289. public void stop() {
  290.  
  291.     tkthread.stop();
  292.  
  293.     }
  294.  
  295.  
  296.  
  297. public void run() {
  298.  
  299.     Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
  300.  
  301.     while (true) {
  302.  
  303.       try {Thread.sleep( 10 ); } catch (InterruptedException e){}
  304.  
  305.       repaint();
  306.  
  307.       }
  308.  
  309.     }
  310.  
  311.  
  312.  
  313. public void paint(Graphics tk) {
  314.  
  315.     tksize = size();
  316.  
  317.     tk.setFont(tkfont);
  318.  
  319.     FontMetrics tkfm = tk.getFontMetrics();
  320.  
  321.     tktexthgt = ( tktexthgt==0 ) ? tkfm.getHeight() : tktexthgt;
  322.  
  323.     tktextasc = ( tktextasc==0 ) ? tkfm.getAscent() : tktextasc;
  324.  
  325.     tktextwth = ( tktextwth==0 ) ? tkfm.stringWidth( tktext ) : tktextwth;
  326.  
  327.     tkwrapwth = ( tkwrapwth==0 ) ? tkfm.stringWidth( tkwraptext ) : tkwrapwth;
  328.  
  329.  
  330.  
  331.  
  332.  
  333.     if ( tktitlepos==0 && tktitle!="" ) {
  334.  
  335.        tk.setFont(tktfont);
  336.  
  337.        tkfm = tk.getFontMetrics();
  338.  
  339.        tktitlehgt = tkfm.getHeight() ;
  340.  
  341.        tktitleasc = tkfm.getAscent() ;
  342.  
  343.        tktitlepos  = tktitleasc + 1;      
  344.  
  345.        }
  346.  
  347.  
  348.  
  349.     if ( tktmargin == 0 ) {
  350.  
  351.        tktmargin = tksize.height - ( tktexthgt + tktitlehgt + tktgap + 2 );
  352.  
  353.        tktmargin = ( tktmargin <= 2 ) ? tktmargin : tktmargin / 2;
  354.  
  355.        }
  356.  
  357.  
  358.  
  359.     tktextpos = tktitlehgt + tktgap + tktextasc + tktmargin ;  
  360.  
  361.  
  362.  
  363.     if ( tkbox.equalsIgnoreCase( "3D" ) == false && tkbox.equalsIgnoreCase("BOX") == false ) {
  364.  
  365.        tk.setColor( tktextbackcolor );
  366.  
  367.        tk.clipRect(0,0,tksize.width,tksize.height);
  368.  
  369.        tk.fill3DRect(0,0,tksize.width,tksize.height,true);
  370.  
  371.        }
  372.  
  373.  
  374.  
  375. /* Draw 3D box if required        */
  376.  
  377.  
  378.  
  379.     if ( tkbox.equalsIgnoreCase( "3D" ) ) { 
  380.  
  381.        tkmargin = ( tkmargin<3 ) ? 3 : tkmargin;
  382.  
  383.        tk.setColor( tkboxcolor );
  384.  
  385.        tk.clipRect(0,0,tksize.width,tksize.height);
  386.  
  387.        tk.fill3DRect(0,0,tksize.width,tksize.height,true);
  388.  
  389.        tk.setColor( tkbordercolor);
  390.  
  391.        tk.fill3DRect(tkmargin, tktextpos-tktextasc-2 ,tksize.width-(tkmargin*2), tktexthgt+4, false);
  392.  
  393.        tk.setFont(tktfont);
  394.  
  395.        tk.setColor( tktitlecolor );
  396.  
  397.        tk.drawString( tktitle, tkmargin , tktitlepos + tktmargin );
  398.  
  399.        }
  400.  
  401.  
  402.  
  403. /* Draw plain border if required  */
  404.  
  405.  
  406.  
  407.     if ( tkbox.equalsIgnoreCase( "BOX") ) { 
  408.  
  409.        tkmargin = ( tkmargin<3 ) ? 3 : tkmargin;
  410.  
  411.        tk.setColor( tkboxcolor);
  412.  
  413.        tk.clipRect(0,0,tksize.width,tksize.height);
  414.  
  415.        tk.fillRect(0,0,tksize.width,tksize.height);
  416.  
  417.        tk.setColor( tkbordercolor);
  418.  
  419.        tk.fillRect(tkmargin,tktextpos-tktextasc-2,tksize.width-(tkmargin*2), tktexthgt+4);
  420.  
  421.        tk.setFont(tktfont);
  422.  
  423.        tk.setColor( tktitlecolor );
  424.  
  425.        tk.drawString( tktitle, tkmargin , tktitlepos + tktmargin );
  426.  
  427.        }
  428.  
  429.  
  430.  
  431. /* Set Clipping for scroll window */
  432.  
  433.  
  434.  
  435.     tk.clipRect(tkmargin + 1, tktextpos-tktextasc-1, tksize.width-(tkmargin+1)*2,tktexthgt+2);
  436.  
  437.     tk.setColor(tktextbackcolor);
  438.  
  439.     tk.fillRect(0,0,tksize.width,tksize.height);
  440.  
  441.  
  442.  
  443. /* Calculate text position        */
  444.  
  445.  
  446.  
  447.  
  448.  
  449.     if ( tkwork == "" ) {
  450.  
  451.        if ( tkwrap.equalsIgnoreCase( "Yes") ) {
  452.  
  453.           tkwork = tktext + tkwraptext + tktext ;
  454.  
  455.           tkoffset = tktextwth + tkwrapwth + tktextwth;
  456.  
  457.  
  458.  
  459.           if ( tksize.width > tktextwth ) {
  460.  
  461.              tktemp = tksize.width / tktextwth;
  462.  
  463.           
  464.  
  465.              for ( int i = 0; i < tktemp  ; i = i + 1 ) {
  466.  
  467.                  tkwork = tkwork + tkwraptext + tktext;
  468.  
  469.                  tkoffset = tkoffset + tkwrapwth + tktextwth; 
  470.  
  471.                  } 
  472.  
  473.              tkwork = tkwork + tkwraptext + tkwork;
  474.  
  475.              tkoffset = tkoffset + tkwrapwth + tkoffset;
  476.  
  477.              }
  478.  
  479.           }
  480.  
  481.        else {
  482.  
  483.           tkwork = tktext;
  484.  
  485.           }  
  486.  
  487.        }
  488.  
  489.  
  490.  
  491.     int tkloc = 0;
  492.  
  493.  
  494.  
  495.     if ( tkdirection.equalsIgnoreCase( "Left" ) ) {
  496.  
  497.        if ( tkwrap.equalsIgnoreCase( "Yes") &&  tkpos != -63000 ) {
  498.  
  499.           tkloc = 0 - tkspd;
  500.  
  501.           tkpos = ( tkpos <= (tktextwth + tkwrapwth ) * -1 ) ? tkloc : tkpos - tkspd;
  502.  
  503.           } 
  504.  
  505.        else { 
  506.  
  507.           tkloc = tksize.width;
  508.  
  509.           tkpos = ( tkpos <= tktextwth * -1 ) ? tkloc : tkpos - tkspd;
  510.  
  511.           }
  512.  
  513.     }
  514.  
  515.     else{
  516.  
  517.        if ( tkwrap.equalsIgnoreCase( "Yes") &&  tkpos != 63000 ) {
  518.  
  519.           tkloc = 0 - ( tktextwth + tkwrapwth ) + tkspd;
  520.  
  521.           tkpos = ( tkpos >  -1 ) ? tkloc : tkpos + tkspd;
  522.  
  523.           } 
  524.  
  525.        else { 
  526.  
  527.           if ( tkwrap.equalsIgnoreCase( "Yes" ) ) {
  528.  
  529.              tkloc = 0 - tkoffset;
  530.  
  531.              }
  532.  
  533.           else {
  534.  
  535.              tkloc = 0 - tktextwth;
  536.  
  537.              }
  538.  
  539.           tkpos = ( tkpos > tksize.width ) ? tkloc : tkpos + tkspd;
  540.  
  541.           }
  542.  
  543.     
  544.  
  545.     }
  546.  
  547.  
  548.  
  549. /* Draw scroll text               */
  550.  
  551.  
  552.  
  553.   
  554.  
  555.     tk.setFont(tkfont);
  556.  
  557.     tk.setColor(tktextcolor);
  558.  
  559.     tk.clipRect(tkmargin + 1, tktextpos-tktextasc-1, tksize.width-(tkmargin+1)*2,tktexthgt+2);
  560.  
  561.     tk.drawString( tkwork, tkpos, tktextpos );
  562.  
  563.  
  564.  
  565.  
  566.  
  567.     }
  568.  
  569. }
  570.  
  571.  
  572.  
  573.